//
//  MeCollectionTopView.m
//  高仿萝卜书摘
//
//  Created by 谢俊逸 on 2016/11/25.
//  Copyright © 2016年 谢俊逸. All rights reserved.
//

#import "MeCollectionTopView.h"
#import "XJYHeader.h"


@interface MeCollectionTopView ()<UIScrollViewDelegate>


@property (nonatomic,strong) UIPageControl *pageControl;



@end

@implementation MeCollectionTopView

- (id)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if(self){
        //configure self
        self.backgroundColor = [UIColor whiteColor];
        self.delegate = self;
        self.showsVerticalScrollIndicator = NO;
        self.showsHorizontalScrollIndicator = NO;
        self.pagingEnabled = YES;
        self.scrollsToTop = NO;
        NSUInteger count = 2;
        CGFloat scrollViewW = self.frame.size.width;
        self.contentSize = CGSizeMake(count * scrollViewW, 0);
        NSLog(@"scrollView Content Size = %f",count*scrollViewW);
        //background Color
        self.backgroundColor = [UIColor whiteColor];
        
        
        [self setupUI];
        
    }
    return self;
}

- (void)setupUI{

    //setup leftPageView
    UIView *leftPageView = ({
        leftPageView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
        leftPageView.backgroundColor = [UIColor whiteColor];
        
        //headerButton
        UIButton *headButton = ({
            headButton = [[UIButton alloc]init];
            headButton.frame = RectMake_LFL(10, 10, 70, 70);
            [headButton setImage:[UIImage imageNamed:@"header1"] forState:UIControlStateNormal];
            [headButton addTarget:self action:@selector(headButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
            headButton.backgroundColor = [UIColor whiteColor];
            
            headButton.layer.cornerRadius = 10;
            headButton.layer.masksToBounds = YES;
            
            headButton;
        });
        [leftPageView addSubview:headButton];
        
        
        //name label
        UILabel *nameLabel = [[UILabel alloc]initWithFrame:RectMake_LFL(90, 13, 60, 20)];
        nameLabel.backgroundColor = [UIColor whiteColor];
        nameLabel.text = @"谢俊逸";
        [leftPageView addSubview:nameLabel];
        
        
        //detailLabel
        UILabel *detailLabel = [[UILabel alloc]initWithFrame:RectMake_LFL(90, 48, 200, 20)];
        detailLabel.backgroundColor = [UIColor whiteColor];
        detailLabel.text = @"朝云暮雨";
        detailLabel.textColor = [UIColor lightGrayColor];
        [leftPageView addSubview:detailLabel];
        
        
        //sexImageView
        UIImageView *sexImageView = [[UIImageView alloc]initWithFrame:RectMake_LFL(155,13,15,15)];
        sexImageView.image = [UIImage imageNamed:@"MaleIcon"];
        sexImageView.backgroundColor = [UIColor whiteColor];
        [leftPageView addSubview:sexImageView];
        
    
        //identificationButton
        UIButton *identificationButton = ({
            identificationButton = [[UIButton alloc]initWithFrame:RectMake_LFL(10, 85, 70, 20)];
            identificationButton.backgroundColor = [UIColor whiteColor];
            [identificationButton setImage:[UIImage imageNamed:@"identificationImage"] forState:UIControlStateNormal];
            [identificationButton addTarget:self action:@selector(indentificationButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
            identificationButton;
        });
        [leftPageView addSubview:identificationButton];
        
        
        //attentionButton
        UIButton *attentionButton = ({
            attentionButton = [[UIButton alloc]initWithFrame:RectMake_LFL(90, 85, 63, 20)];
            attentionButton.backgroundColor = [UIColor whiteColor];
            [attentionButton setTitle:@"关注 1" forState:UIControlStateNormal];
            attentionButton.titleLabel.font = [UIFont systemFontOfSize: 14.0];

            [attentionButton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
            [attentionButton addTarget:self action:@selector(attentionButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
            attentionButton;
        });
        [leftPageView addSubview:attentionButton];
        
        
        //fansButton
        UIButton *fansButton = ({
            fansButton = [[UIButton alloc]initWithFrame:RectMake_LFL(158, 85, 63, 20)];
            fansButton.backgroundColor = [UIColor whiteColor];
            fansButton.titleLabel.font = [UIFont systemFontOfSize: 14.0];

            [fansButton setTitle:@"粉丝 1" forState:UIControlStateNormal];
            [fansButton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
            [fansButton addTarget:self action:@selector(fansButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
            fansButton;
        });
        [leftPageView addSubview:fansButton];
        
        
        //groupButton
        UIButton *groupButton = ({

            groupButton = [[UIButton alloc]initWithFrame:RectMake_LFL(226, 85, 63, 20)];
            groupButton.titleLabel.font = [UIFont systemFontOfSize: 14.0];
            groupButton.backgroundColor = [UIColor whiteColor];
            [groupButton addTarget:self action:@selector(groupButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
            [groupButton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
            [groupButton setTitle:@"萝卜坑 1" forState:UIControlStateNormal];
            groupButton;
        });
        [leftPageView addSubview:groupButton];
        
        
        leftPageView;
    });
    [self addSubview:leftPageView];
    
    
    CGFloat scrollViewW = self.frame.size.width;
    //setup rightPageView
    UIView *rightPageView = ({
        rightPageView =  [[UIView alloc]initWithFrame:CGRectMake(scrollViewW, 0, self.frame.size.width, self.frame.size.height)];
        rightPageView.backgroundColor = [UIColor whiteColor];
        
        
        //Textlabel
        UILabel *textLabel = ({
            textLabel = [[UILabel alloc]initWithFrame:RectMake_LFL(self.frame.size.width/2 - 120, 30, 260, 70)];
            textLabel.numberOfLines = 2;
            textLabel.backgroundColor = [UIColor whiteColor];
            
            //设置被转发微博retweetContentLabel缩进
            NSMutableParagraphStyle *style = [[NSMutableParagraphStyle defaultParagraphStyle] mutableCopy];
            //style.headIndent = self.statusFrame.retweetNameLabelF.size.width;
            style.firstLineHeadIndent = 25;
            NSString *textString = @"发布书摘0次，随笔三次，读过0本书，过去一个月中读过0本书";
            //设置Label的attributedText属性后无需再设置UILabel的text属性，因为attributedString初始化的时候已经设置过了
            textLabel.attributedText =
            [[NSAttributedString alloc] initWithString:textString attributes:@{NSParagraphStyleAttributeName:style}];
            textLabel;
        });
        [rightPageView addSubview:textLabel];
        
        
        rightPageView;

    });
    
    [self addSubview:rightPageView];
}

#pragma mark ButtonClicked
- (void)headButtonClicked:(UIButton *)button{
    NSLog(@"headButtonClicked");
}

- (void)indentificationButtonClicked:(UIButton *)button{
    NSLog(@"indentificationButtonClicked");
}

- (void)attentionButtonClicked:(UIButton *)button{
    NSLog(@"attentionButtonClicked");
}


- (void)fansButtonClicked:(UIButton *)button{
    NSLog(@"fansButtonClicked");
    
}

- (void)groupButtonClicked:(UIButton *)button{
    NSLog(@"groupButtonClicked");
}
#pragma mark UIScrollViewDelegate 

-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
    //NSLog(@"scroll");
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    long currentPage = lround( self.contentOffset.x / CGRectGetWidth(self.frame) );
    [self.XJYTopScrollViewDelegate XJYTopScrollCurremtPage:currentPage];
}

@end
